package com.missilike.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.biz.IMilMessagePushService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.core.utils.SecurityUtils;
import com.missilike.repository.entity.MilMessagePush;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 主动消息推送 前端控制器
 * </p>
 *
 * @author kin
 * @since 2019-01-02
 */
@RestController
@RequestMapping("api/mil/message_push")
public class MilMessagePushController {

    private final IMilMessagePushService milMessagePushService;

    @Autowired
    public MilMessagePushController(IMilMessagePushService milMessagePushService) {
        this.milMessagePushService = milMessagePushService;
    }

    @RequestMapping(value = "page", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize) {
        IPage<MilMessagePush> messageList = milMessagePushService.page(new Page<>(pageNum, pageSize),null);
        return ResultUtils.ok(messageList);
    }

    @RequestMapping(value = "push", method = RequestMethod.POST)
    public CommonResult save(@RequestBody MilMessagePush milMessagePush) {
        milMessagePush.setCreateUserId(SecurityUtils.getCurrentUserId());
        milMessagePush.setStatus(2);
        milMessagePushService.save(milMessagePush);
        milMessagePushService.messagePush(milMessagePush);
        return ResultUtils.ok();
    }
}

